package com.mercator.client.util;

import java.util.ArrayList;
import java.util.Collection;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;



public final class JSONGeneArray extends JavaScriptObject {
	
	protected JSONGeneArray() { 
	};
	
	public final static native JSONGeneArray create(JavaScriptObject c)/*-{
		return c;
	}-*/;

	public final static Collection<String> iterator(JSONGeneArray jarray) {
		ArrayList<String> al = new ArrayList<String>();
	//	Window.alert(getKeys().toString());
		
		JsArrayString array = getKeys(jarray);
		
		for (int i = 0; i < array.length(); i++) {
			al.add(array.get(i));
			//Window.alert("loop");
		}
		
		return al;
	}

	private static final native JsArrayString getKeys(JSONGeneArray array)/*-{
		return Object.keys(array);
	}-*/;

	public final native JSONGene get(String prop)/*-{
		return eval(this)[eval(prop)];
	}-*/;

}
